package cn.lingyangwl.agile.infra.weixin.cp.listener;

import cn.lingyangwl.agile.dynamic.config.core.event.ConfigDeleteEvent;
import cn.lingyangwl.agile.infra.weixin.cp.process.WxCpProcess;
import cn.lingyangwl.agile.model.enums.ConfigKeyEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author shenguangyang
 */
@Slf4j
@Component
public class WxCpConfigDeleteListener {
    @Resource
    private WxCpProcess process;

    @EventListener(ConfigDeleteEvent.class)
    public void delete(ConfigDeleteEvent event) {
        Object configKey = event.getSource();
        if (ConfigKeyEnum.WX_CP.getKey().equals(configKey)) {
            process.deleteCache();
            log.info("delete weixin cp client: {}", configKey);
        }
    }
}
